package com.yztstudy.Controller;

import com.yztstudy.Service.UserService;
import com.yztstudy.entity.User;
import com.yztstudy.param.CartListParam;
import com.yztstudy.param.PageParam;
import com.yztstudy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 超级管理员调用用户的表示层
 */

@RestController
@RequestMapping("/user")
public class AdminUserController {

    @Autowired
    private UserService userService;


    /**
     * TODO 分页查询用户列表
     * @param pageParam 分页参数
     * @return
     */
    @PostMapping("/admin/list")
    public R listPage(@RequestBody PageParam pageParam)
    {
        return userService.listPage(pageParam);
    }


    /**
     * TODO 删除某一个用户
     * @param cartListParam 用户的ID
     * @return
     */
    @PostMapping("/admin/remove")
    public R remove(@RequestBody CartListParam cartListParam)
    {
        return userService.remove(cartListParam);
    }


    /**
     * TODO 更新用户
     * @param user 用户
     * @return
     */
    @PostMapping("/admin/update")
    public R update(@RequestBody User user)
    {
        return userService.update(user);
    }


    /**
     * TODO 添加用户
     * @param user 用户
     * @return
     */
    @PostMapping("/admin/save")
    public R save(@RequestBody User user)
    {
        return userService.register(user);
    }
}
